package indi.caibo.service_edu.controller;


import indi.caibo.commonutils.R;
import indi.caibo.service_edu.entity.vo.subject.SubjectNestedVo;
import indi.caibo.service_edu.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author Bo Cai
 * @since 2021-10-06
 */
@Api(tags = "课程分类管理模块")
@RestController
@RequestMapping("/edu-service/subject")
public class EduSubjectController {
    @Autowired
    private EduSubjectService subjectService;

    @ApiOperation("Excel批量导入课程分类")
    @PostMapping("import")
    public R addSubject(@ApiParam(name = "file", value = "需要解析的文件", required = true)
                        @RequestPart("file") MultipartFile file) {
        //1 获取上传的excel文件 MultipartFile
        subjectService.importSubjectData(file, subjectService);
        //判断返回集合是否为空
        return R.ok();
    }

    @ApiOperation("嵌套数据列表")
    @GetMapping("")
    public R nestedList(){
        List<SubjectNestedVo> subjectNestedVoList = subjectService.nestedList();
        return R.ok().data("items", subjectNestedVoList);
    }
}

